﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZRT.RHPX.Entity;
using ZRT.RHPX.Repository;

namespace ZRT.RHPX.Service
{
    public class SysMenuService
    {
        public SysMenuRepository MenuRepository { get; private set; }

        public SysMenuService()
        {
            MenuRepository = new SysMenuRepository();
        }

        public IEnumerable<SysMenu> Query()
        {
            return MenuRepository.Query();
        }

        public Object GetSonMenu(List<SysMenu> AllMenu, int ParentID)
        {
            var Model = from m in AllMenu
                        where m.ParentID != null && m.ParentID == ParentID
                        select new
                        {
                            ID = m.ID,
                            text = m.MenuName,
                            FullName = m.MenuName,
                            NavigateUrl = m.NavigateUrl,
                            IconCss = m.IconCss,
                            state = "open",
                            children = GetSonMenu(AllMenu, m.ID)
                        };
            return Model;
        }
    }
}
